package com.klz.iblog.controller;

import com.klz.iblog.common.Constants;
import com.klz.iblog.common.Result;
import com.klz.iblog.common.ResultGenerator;
import com.klz.iblog.pojo.Comments;
import com.klz.iblog.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = {"comments接口"})
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    @ApiOperation(value = "查询所有博客的评论量")
    @GetMapping("/selectAllCommentsCounts")
    public Result<Integer> selectAllCommentsCounts() {
        try{
            return ResultGenerator.genSuccessResult(commentsService.selectAllCommentsCounts());
        }catch (Exception e) {
            return ResultGenerator.genErrorResult(Constants.RESULT_CODE_SERVER_ERROR,"服务器异常-->"+e.getMessage());
        }
    }

    @ApiOperation(value = "查询该评论的所有回复")
    @GetMapping("/selectCommentsAllReplys")
    public Result<Comments> selectCommentsAllReplys(@RequestParam("commentsId") Integer commentsId) {
        try{
            return ResultGenerator.genSuccessResult(commentsService.selectCommentsAllReplys(commentsId));
        }catch (Exception e) {
            return ResultGenerator.genErrorResult(Constants.RESULT_CODE_SERVER_ERROR,"服务器异常-->"+e.getMessage());
        }
    }

    @ApiOperation(value = "查询该评论的所有回复总数")
    @GetMapping("/selectCommentsAllReplysCount")
    public Result<Integer> selectCommentsAllReplysCount(@RequestParam("commentsId") Integer commentsId) {
        try{
            return ResultGenerator.genSuccessResult(commentsService.selectCommentsAllReplysCount(commentsId));
        }catch (Exception e) {
            return ResultGenerator.genErrorResult(Constants.RESULT_CODE_SERVER_ERROR,"服务器异常-->"+e.getMessage());
        }
    }
}
